home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 409_01 / model.mac < prev    next >
Text File  |  1993-09-17  |  6KB  |  225 lines

  1. ;****************************************************************************
  2. ;*
  3. ;*                  Copyright (C) 1993 Kendall Bennett.
  4. ;*                          All rights reserved.
  5. ;*
  6. ;* Filename:    $RCSfile: model.mac $
  7. ;* Version:     $Revision: 1.5 $
  8. ;*
  9. ;* Language:    Turbo Assembler 2.5
  10. ;* Environment: IBM PC (MS DOS)
  11. ;*
  12. ;* Description: Macros to provide memory model independant assembly language
  13. ;*              module for Borland C++.
  14. ;*
  15. ;* NOTES:   When you declare the data and code segments, you should specify
  16. ;*          a name to be used. This name should be the name of the file
  17. ;*          being assembled, but you may use the same name for mutiple
  18. ;*          modules if you wish so that the data and code for these modules
  19. ;*          are all contained in the same segments. Of course the maximum
  20. ;*          size of data and code must be less than 64k respectively.
  21. ;*
  22. ;* $Id: model.mac 1.5 1992/06/10 01:11:16 kjb release $
  23. ;*
  24. ;* Revision History:
  25. ;* -----------------
  26. ;*
  27. ;* $Log: model.mac $
  28. ;* Revision 1.5  1992/06/10  01:11:16  kjb
  29. ;* Optimised for faster polygon/line scan conversion.
  30. ;*
  31. ;* Revision 1.4  92/04/24  16:32:38  kjb
  32. ;* Fixed bug in declaration of data segment in HUGE model (again!)
  33. ;* 
  34. ;* Revision 1.3  92/01/01  21:35:42  kjb
  35. ;* Fixed bug in declaration of data segment for the HUGE data model.
  36. ;* 
  37. ;* Revision 1.2  91/11/12  11:36:14  kjb
  38. ;* Added macro for static model independant procedures.
  39. ;* 
  40. ;* Revision 1.1  91/09/20  16:26:07  kjb
  41. ;* Initial revision
  42. ;* 
  43. ;****************************************************************************
  44.  
  45. ; Define symbols codesize and datasize depending on the requested memory
  46. ; model.
  47.  
  48. ifdef   __TINY__
  49.         codesize    EQU 0
  50.         datasize    EQU 0
  51.         hugedata    EQU 0
  52. else
  53. ifdef   __MEDIUM__
  54.         codesize    EQU 1
  55.         datasize    EQU 0
  56.         hugedata    EQU 0
  57. else
  58. ifdef   __COMPACT__
  59.         codesize    EQU 0
  60.         datasize    EQU 1
  61.         hugedata    EQU 0
  62. else
  63. ifdef   __LARGE__
  64.         codesize    EQU 1
  65.         datasize    EQU 1
  66.         hugedata    EQU 0
  67. else
  68. ifdef   __HUGE__
  69.         codesize    EQU 1
  70.         datasize    EQU 1
  71.         hugedata    EQU 1
  72. else
  73.         codesize    EQU 0       ; Default to small model if none specified
  74.         datasize    EQU 0
  75.         hugedata    EQU 0
  76. endif
  77. endif
  78. endif
  79. endif
  80. endif
  81.  
  82. ; Macros for obtaining size of pointer for model requested.
  83.  
  84. if datasize
  85.         DPTR        EQU DWORD
  86.         dptrsize    EQU 4       ; Size of a data pointer
  87. else
  88.         DPTR        EQU WORD
  89.         dptrsize    EQU 2
  90. endif
  91.  
  92. if codesize
  93.         CPTR        EQU DWORD
  94.         FPTR        EQU FAR
  95.         cptrsize    EQU 4       ; Size of a code pointer
  96. else
  97.         CPTR        EQU WORD
  98.         FPTR        EQU NEAR
  99.         cptrsize    EQU 2
  100. endif
  101.  
  102. ; Macros for procedure definitions given a name. Note that they also exports
  103. ; the symbol with the PUBLIC directive, so that it need not be explicitly
  104. ; exported.
  105.  
  106. MACRO   procstart name          ; Set up model independant proc
  107. if codesize                     ; and export name
  108. PROC    name FAR
  109. else
  110. PROC    name NEAR
  111. endif
  112.         PUBLIC name
  113. ENDM
  114.  
  115. MACRO   procstatic name         ; Set up model independant private proc
  116. if codesize
  117. PROC    name FAR
  118. else
  119. PROC    name NEAR
  120. endif
  121. ENDM
  122.  
  123. MACRO   procnear name           ; Set up near proc
  124. PROC    name NEAR               ; and export name
  125.         PUBLIC name
  126. ENDM
  127.  
  128. MACRO   procfar name            ; Set up far proc
  129. PROC    name FAR                ; and export name
  130.         PUBLIC name
  131. ENDM
  132.  
  133. MACRO   procend name            ; End procedure macro
  134. ENDP    name
  135. ENDM
  136.  
  137. ; Macros for the _BSS data segment. This segment contains uninitialised data.
  138.  
  139. MACRO   begbssseg
  140. SEGMENT _BSS WORD PUBLIC 'BSS'
  141. ENDM
  142.  
  143. MACRO   endbssseg
  144. ENDS    _BSS
  145. ENDM
  146.  
  147. ; Macros for the _DATA data segment. This segment contains initialised data.
  148.  
  149. MACRO   begdataseg name
  150. ifdef   __HUGE__
  151. SEGMENT &name&_DATA WORD PUBLIC 'DATA'
  152. else
  153. SEGMENT _DATA WORD PUBLIC 'DATA'
  154. endif
  155. ENDM
  156.  
  157. MACRO   enddataseg name
  158. ifdef   __HUGE__
  159. ENDS    &name&_DATA
  160. else
  161. ENDS    _DATA
  162. endif
  163. ENDM
  164.  
  165. ; Macro to be invoked at the start of all modules to set up segments for
  166. ; later use.
  167.  
  168. MACRO   header name
  169. begdataseg name
  170. enddataseg name
  171. begbssseg
  172. endbssseg
  173. ENDM
  174.  
  175. ; Macro for the main code segment.
  176.  
  177. MACRO   begcodeseg name
  178. if codesize
  179. SEGMENT &name&_TEXT BYTE PUBLIC 'CODE'
  180. ifdef   __HUGE__
  181. GROUP   DGROUP &name&_DATA
  182.         ASSUME CS:&name&_TEXT,DS:DGROUP
  183. else
  184. GROUP   DGROUP _DATA,_BSS
  185.         ASSUME CS:&name&_TEXT,DS:DGROUP
  186. endif
  187. else
  188. SEGMENT _TEXT BYTE PUBLIC 'CODE'
  189. GROUP   DGROUP _DATA,_BSS
  190.         ASSUME CS:_TEXT,DS:DGROUP
  191. endif
  192. ENDM
  193.  
  194. MACRO   endcodeseg name
  195. if codesize
  196. ENDS    &name&_TEXT
  197. else
  198. ENDS    _TEXT
  199. endif
  200. ENDM
  201.  
  202. ; Macros for entering and leaving procedures. Here we automatically save
  203. ; the SI and DI registers that are used as register variables by Borland C++.
  204. ; We also save the DS register in the HUGE model and make it point to our
  205. ; data segment. Upon leaving all registers are restored.
  206.  
  207. MACRO   setupDS
  208.         push    si                      ; Save register variables
  209.         push    di                      ; For Borland C++
  210.  
  211.     IF  hugedata
  212.         push    ds                      ; Save DS
  213.         mov     ax,DGROUP               ; Address our data segment
  214.         mov     ds,ax
  215.     ENDIF
  216. ENDM
  217.  
  218. MACRO   restoreDS
  219.     IF  hugedata
  220.         pop     ds
  221.     ENDIF
  222.         pop     di
  223.         pop     si
  224. ENDM
  225.